package com.zj.web.controller;

import com.zj.service.ReviewService;
import com.zj.web.bean.ResponseResult;
import com.zj.web.bean.ReviewsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/auth/reviews")
@RefreshScope //开启动态刷新
public class ReviewController {
    @Autowired
    private ReviewService reviewService;
    //添加评论
    @PostMapping("/add")
    public ResponseEntity<ResponseResult> addReview(ReviewsDTO reviewsDTO){
        ReviewsDTO reviewsDTO1 = reviewService.addReview(reviewsDTO);
        return ResponseEntity.ok(ResponseResult.ok().setdata(reviewsDTO1));
    }
    //根据商品ID获取评论列表
    @GetMapping("/product/{productId}")
    public ResponseEntity<ResponseResult> getReviewsByProductId(@PathVariable Long productId){
        List<ReviewsDTO> reviewsDTOList = reviewService.getReviewsByProductId(productId);
        return ResponseEntity.ok(ResponseResult.ok().setdata(reviewsDTOList));
    }
    //根据商品ID和评分获取评论列表
    @GetMapping("/product/{productId}/{rating}")
    public ResponseEntity<ResponseResult> getReviewsByProductIdAndRating(@PathVariable Long productId,@PathVariable Integer rating){
        List<ReviewsDTO> reviewsDTOList = reviewService.getReviewByIdAndRating(productId,rating);
        return ResponseEntity.ok(ResponseResult.ok().setdata(reviewsDTOList));
    }
}
